package com.yyjj.yyjj.home.service.impl;

import com.yyjj.yyjj.client.product.ProductFeignClient;
import com.yyjj.yyjj.client.search.SearchFeignClient;
import com.yyjj.yyjj.client.user.UserFeignClient;
import com.yyjj.yyjj.home.service.HomeService;
import com.yyjj.yyjj.model.product.Category;
import com.yyjj.yyjj.model.product.SkuInfo;
import com.yyjj.yyjj.model.search.SkuEs;
import com.yyjj.yyjj.vo.user.LeaderAddressVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class HomeServiceImpl implements HomeService {

    @Autowired
    private UserFeignClient userFeignClient;

    @Autowired
    private ProductFeignClient productFeignClient;

    private SearchFeignClient searchFeignClient;

    //首页数据显示
    @Override
    public Map<String, Object> homeData(Long userId) {
        //根据userId获取当前登录用户提货地址信息  service-user
        Map<String,Object> result=new HashMap<>();
        LeaderAddressVo leaderAddressVo = userFeignClient.getUserAddressByUserId(userId);
        result.put("leaderAddressVo",leaderAddressVo);
        //获取所有分类 service-product
        List<Category> allCategoryList = productFeignClient.findAllCategoryList();
        result.put("categoryList",allCategoryList);
        //获取新人专享 service-product
        List<SkuInfo> personSkuInfoList = productFeignClient.findNewPersonSkuInfoList();
        result.put("newPersonSkuInfoList",personSkuInfoList);
        //获取爆款产品  service-search
        //根据score进行降序排列
        List<SkuEs> hotSkuList = searchFeignClient.findHotSkuList();
        result.put("hotSkuList",hotSkuList);
        //封装获取的数据到map集合,返回
        return result;
    }
}
